from abc import abstractmethod, ABCMeta

from Attriabte import Color
from ..Layout.LayoutSide import LayoutSide
import customtkinter as ctk
import tkinter as tk

class BodyFrame(metaclass=ABCMeta):
    """
    主菜单Frame
    """

    def __init__(
            self,
            layout: LayoutSide,
            with_scoller=False
    ):
        """

        :param layout: 所处布局
        """
        self.layout = layout
        self.ws = with_scoller
        self.init_frame()

    def init_frame(self):
        self.frame_in = self.layout.Data.getFrameInstance(
            with_scoller=self.ws
        )
        if isinstance(self.frame_in, list):
            self.frame = self.frame_in[1]
            self.frame_type = "scoller"
            print(",,,", self.frame)
        else:
            self.frame = self.frame_in
            self.frame_type = "basic"

        self.frame_width = self.frame.winfo_width()
        self.frame_height = self.frame.winfo_height()

    @abstractmethod
    def pack(self):
        """
        frame的布局
        :return:
        """

    def get(self):
        '''
        获取
        :return:
        '''
        self.init_frame()

        self.pack()
        return self.frame_in, self

    def to(self, page):
        self.layout.body(page)

    def basicTheme(self, title):
        """
        中间一个黑块带标题的基础样式
        :param title:
        :return:
        """
        width, height = .8, .8
        self.middle_frame = ctk.CTkFrame(self.frame)
        ctk.CTkLabel(self.frame, text=f"  | {title}", text_font=('黑体', 20), anchor=tk.W).place(
            relheight=(1 - height) / 2,
            x=0,
            y=0
        )

        self.middle_frame.place(
            relwidth=width,
            relheight=height,
            relx=(1 - width) / 2,
            rely=(1 - height) / 2
        )

        inner_w = .5
        inner_h = .4

        self.attribate_basic = {
            "bg": Color.cutkinter
        }

        self.inner_frame = tk.Frame(self.middle_frame, **self.attribate_basic)
        self.inner_frame.place(
            relx=(1 - inner_w) / 2,
            rely=(1 - inner_h) / 2,
            relwidth=inner_w,
            relheight=inner_h,
        )

